package com.cskaoyan.controller.comment;

import com.cskaoyan.bean.MallComment;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.comment.commentlist.WxCommentCountVo;
import com.cskaoyan.model.vo.comment.commentlist.WxCommentListVo;
import com.cskaoyan.service.comment.WxCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @program: project-market
 * @description:
 * @author: zhijie
 * @create: 2021-12-02 22:06
 **/
@RequestMapping("wx/comment")
@RestController
public class WxCommentController {
    @Autowired
    WxCommentService wxCommentService;

    /**
     * 显示当前商品 type的已评价内容
     *
     * @param valueId
     * @param type
     * @param limit
     * @param page
     * @param showType
     * @return
     */
    @GetMapping("list")
    public BaseRespVo commentList(Integer valueId, Integer type, Integer limit, Integer page, Integer showType) {
        WxCommentListVo data = wxCommentService.commentList(valueId, type, limit, page, showType);
        return BaseRespVo.ok(data);
    }

    /**
     * 统计全部评价以及有图评价数量
     *
     * @param valueId
     * @param type
     * @return
     */
    @GetMapping("count")
    public BaseRespVo commentCount(Integer valueId, Integer type) {
        WxCommentCountVo data = wxCommentService.commentCount(valueId, type);
        return BaseRespVo.ok(data);
    }

    /**
     * 新增留言
     *
     * @param mallComment
     * @return
     */
    @PostMapping("post")
    public BaseRespVo commentPost(@RequestBody MallComment mallComment, HttpSession session) {
        Integer userId = (Integer) session.getAttribute("uid");
        MallComment data = wxCommentService.commentPost(mallComment, userId);
        return BaseRespVo.ok(data);
    }
}
